<?php
/*
 * PHP Account creator for Trinity
 * Copyright (C) 2010 Shocker @ WoW.Freakz.ro
*/

include("config.php");
?>
<html>
<head>
 <title>PHP Account creator for Trinity by Shocker @ WoW.Freakz.ro</title>
 <link rel="stylesheet" type="text/css" href="themes/<?php echo $_THEME;?>/css.css">
</head>

<body>
<br><br><center><b><?php echo $_LANG['page_subtitle'];?></b><br><br>
<?php
if (isset($_POST['submit']))
{
    $email = preg_replace('/[^a-zA-Z0-9\@\-\_\.]/', '', $_POST['mail']);
    $user = strtoupper($_POST['user']);
    $len_pass = strlen($_POST['pass']);
    $len_user = strlen($user);
    $pass = sha1("$user:" . strtoupper($_POST['pass']));
    
    if (!preg_match('/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/', strtoupper($email)) || $email != $_POST['mail'])
        $msg = $_LANG['invalid_email'];
    else if (preg_match('/[^a-zA-Z0-9\_]/', $user))
        $msg = $_LANG['invalid_user'];
    else if (mysql_num_rows(mysql_query("SELECT id FROM realmd.account WHERE username = '$user'")))
        $msg = $_LANG['user_exists'];
    else if (mysql_num_rows(mysql_query("SELECT id FROM realmd.account WHERE email = '$email'")))
        $msg = $_LANG['email_exists'];
    else if ($len_pass < $_PASS_LENGTH['min'] || $len_pass > $_PASS_LENGTH['max'])
        $msg = sprintf($_LANG['invalid_pass_len'], $_PASS_LENGTH['min'], $_PASS_LENGTH['max']);
    else if ($len_user < $_USER_LENGTH['min'] || $len_user > $_USER_LENGTH['max'])
        $msg = sprintf($_LANG['invalid_user_len'], $_PASS_LENGTH['min'], $_PASS_LENGTH['max']);
    else
        if (mysql_query("INSERT INTO realmd.account (username, sha_pass_hash, email, last_ip) VALUES('$user', '$pass', '$email', '{$_SERVER['REMOTE_ADDR']}')"))
        {
            $msg = $_LANG['complete'];
            unset($_POST);
        }
        else
            $msg = $_LANG['error_create'];
            
    echo "<div class='error'>$msg</div><br><br>";
}
?>
<form method="POST">
    <table>
        <tr><td><?php echo $_LANG['page_user'];?></td><td><input type='text' name='user' value="<?php echo htmlentities(@$_POST['user']);?>"></td></tr>
        <tr><td><?php echo $_LANG['page_pass'];?></td><td><input type='text' name='pass' value="<?php echo htmlentities(@$_POST['pass']);?>"></td></tr>
        <tr><td><?php echo $_LANG['page_email'];?></td><td><input type='text' name='mail' value="<?php echo htmlentities(@$_POST['mail']);?>"></td></tr>
        <tr><td>&nbsp;</td><td><input type="submit" name="submit" value="<?php echo $_LANG['page_register'];?>"></td>
    </table>
</form>
</center>
</body>
</html>